﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

/// <summary>
///ZJLX 的摘要说明
/// </summary>
public partial class ZJLX
{
    public enum typeZJLX { 充值 = 1, 转账, 提现, 收款, 付款 }
    public enum statusZJLX { 冻结 = 1, 处理失败, 处理成功 }
    public static ZJLX GetByAddUserID(int id)
    {

        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.ZJLX.FirstOrDefault(row => row.AddUserID == id);
        }
    }

    public static List<ZJLX> GetAll()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.ZJLX.ToList();
        }
    }

    public void Add()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            context.ZJLX.InsertOnSubmit(this);
            context.SubmitChanges();
        }
    }

    public void Update()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            this.GetType().GetMethod("Detach").Invoke(this, null);
            var tbl = context.GetTable<ZJLX>();
            tbl.Attach(this);
            context.Refresh(RefreshMode.KeepCurrentValues, this);
            context.SubmitChanges();
        }
    }

    public static void Delete(int id)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var objItem = context.ZJLX.FirstOrDefault(row => row.AddUserID == id);
            if (objItem == null)
                return;
            context.ZJLX.DeleteOnSubmit(objItem);
            context.SubmitChanges();
        }
    }

    public static void BadDelete(int ID)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            ZJLX objZJLX = ZJLX.GetByAddUserID(ID);
            if (objZJLX == null)
                return;
            objZJLX.Enable_Flag = 0;
            objZJLX.Update();
        }
    }

    public static List<ZJLX> GetAllByConditon(int userID, string txtLDZJFrom, string txtLDZJTo,string des,string remark,int sendUserID, string AddTimeForm, string AddTimeTo, int typeZJLX,int statusZJLX)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var query = from t in context.ZJLX
                        where t.Enable_Flag == 1
                        select t;
            if (userID != 0)
                query = query.Where(row => row.AddUserID == userID);
            if (!string.IsNullOrEmpty(txtLDZJFrom))
                query = query.Where(row => row.Money >= DongDong.Common.Misc.ConvertToDecimal(txtLDZJFrom));
            if (!string.IsNullOrEmpty(txtLDZJTo))
                query = query.Where(row => row.Money <= DongDong.Common.Misc.ConvertToDecimal(txtLDZJTo));
            if (!string.IsNullOrEmpty(des))
                query = query.Where(row => row.Des.Contains(des));
            if (!string.IsNullOrEmpty(remark))
                query = query.Where(row => row.Remark.Contains(remark));
            if (sendUserID != 0)
                query = query.Where(row => row.SendUserID == sendUserID);
            if (!string.IsNullOrEmpty(AddTimeForm))
                query = query.Where(row => row.AddTime >= DongDong.Common.Misc.ConvertToDateTime(AddTimeForm));
            if (!string.IsNullOrEmpty(AddTimeTo))
                query = query.Where(row => row.AddTime <= DongDong.Common.Misc.ConvertToDateTime(AddTimeTo));
            if (typeZJLX != 0)
                query = query.Where(row => row.Type == typeZJLX);
            if (statusZJLX != 0)
                query = query.Where(row => row.Status == statusZJLX);
            query = query.OrderByDescending(row => row.AddTime);
            return query.ToList();
        }
    }
}